package com.daiqile.myinterest.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;

import com.daiqile.myinterest.R;
import com.daiqile.myinterest.adapter.HeaderAdapter;
import com.daiqile.myinterest.model.HelpListDTO;
import com.daiqile.myinterest.utils.HeaderProductLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class SecondActivity extends AppCompatActivity {

    @BindView(R.id.recycleView)
    RecyclerView mRecyclerView;
    @BindView(R.id.header_product_image)
    ImageView mImageView;
    HeaderProductLayout mHeaderView;
    int imageY = 0;
    private List<HelpListDTO> helpList = new ArrayList<>();
    private HeaderAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);
        ButterKnife.bind(this);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mHeaderView = new HeaderProductLayout(this);
         adapter = new HeaderAdapter(null);
        adapter.addHeaderView(mHeaderView);
        mRecyclerView.setAdapter(adapter);
        mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
                int[] location = new int[2];
                mImageView.getLocationOnScreen(location);
                int y = location[1];
                imageY = y;
            }

            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                if (mHeaderView == null) return;
                int getTop = mHeaderView.getDistanceY();
                if (getTop <= imageY) {
                    mImageView.setVisibility(View.VISIBLE);
                } else {
                    mImageView.setY(0);
                    mImageView.setVisibility(View.GONE);
                }
            }
        });
        initHelpList();
    }
    private void initHelpList() {
        for (int i =0;i<2 ;i++){
            HelpListDTO a = new HelpListDTO("1、还款方式","1)使用本人绑定银行卡还款\n2)支付宝知道还款账户;");
            helpList.add(a);
            HelpListDTO b = new HelpListDTO("2、申请条件","年满18-30周岁，非学生，本人实名制手机号码且连续使用时间满6个月以上即可尝试申请。");
            helpList.add(b);
            HelpListDTO c = new HelpListDTO("3、审核不通过原因","小草钱包系统是通过大数据分析自动审核，由于您的综合评分不足，因此借款申请暂未获得批准，如和人资料无重大变化，不想建议短期内再次申请");
            helpList.add(c);
            HelpListDTO d = new HelpListDTO("4、姓名或身份证填写有误","为了您的账号信息安全，暂时不可以修改，因为姓名和身份证明是你的唯一标识，建议联系客服处理。");
            helpList.add(d);
        }
        adapter.addData(helpList);
    }
}
